<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:f="http://java.sun.com/jsf/core">

    <!--
    
    Copyright 2007-2012 Audrius Valunas

    This file is part of LibreACS.

    LibreACS is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    LibreACS is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with LibreACS.  If not, see <http://www.gnu.org/licenses/>.

    -->

    <ui:composition template="device_template.xhtml">
        <ui:define name="title">Device management</ui:define>
        <ui:define name="body">
            <h4><h:outputText value="#{Software.new ? 'New firmware image' : Software.version}" /></h4>
            <p>Here you can set firmware for device.</p>
            <h:form id="swform">
                <h:inputHidden value="#{HwModel.id}"/>
                <h:inputHidden value="#{Config.hwid}"/>
                <h:inputHidden value="#{Software.hwid}"/>
                <h:inputHidden value="#{Software.version}"/>
                <h:panelGrid columns="1">
                    <h:outputText value="Version:"  rendered="#{Software.new}"/>
                    <h:inputText value="#{Software.version}"  binding="#{Software.versionin}" rendered="#{Software.new}"/>
                    <h:outputText value="Firmware image file:" />
                    <h:panelGrid columns="2">
                        <h:selectOneMenu  id="fwlist" value="#{Software.filename}" >
                            <f:selectItems   value="#{Software.files}" />
                        </h:selectOneMenu>
                        <a4j:commandButton value="Rm" action="#{Software.deleteFwFile}" reRender="fwlist" />
                    </h:panelGrid>

                    <rich:fileUpload fileUploadListener="#{Software.uploadListener}"
                                     maxFilesQuantity="10000"
                                     id="upload"
                                     autoclear="true"
                                     onsizerejected="javascript:alert('too big')"
                                     ontyperejected="javascript:alert('bad type')"
                                     addControlLabel="Upload firmware ..."
                                     immediateUpload="true"
                                     listHeight="65"
                                     >
                        <a4j:support event="onuploadcomplete" reRender="fwlist" />
                    </rich:fileUpload>
                </h:panelGrid>
                <div style="display: #{Software.new ? 'none' : 'block'}">
                    <h:commandButton class="rich-button" value="Save" action="#{Software.Save}" />
                    <h:commandButton class="rich-button" value="Delete" action="#{Software.Delete}" onclick="if (!confirm('Are you sure?')) { return false; }"/>
                </div>
                <div style="display: #{Software.new ? 'block' : 'none'}">
                    <h:commandButton class="rich-button" type="submit" value="Create" action="#{Software.Create}" />
                </div>

            </h:form>
        </ui:define>
    </ui:composition>
</html>